home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-04-03 | 8.1 KB | 314 lines | [TEXT/KAHL] |
-
-
- void
- DoColorizedCopyBits()
- {
- Rect srcRect;
- long * bitsPtr;
- short iii;
- long jjj;
- RGBColor myrgb, savergb;
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
- unsigned short myRowBytes;
- char mode;
-
- SetRect( &srcRect, 0, 0, 1, 256 ); /*left, top, right, bottom */
- if( !NewGWorld( &myOffGWorld, 32, &srcRect, 0, 0, 0 ) )
- {
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- /*--- myPixMapHandle = myOffGWorld->portPixMap; -----pre-7.0 */
- LockPixels( myPixMapHandle );
-
-
- /* get baseAddr good in 32-bit mode */
- bitsPtr = (long *) GetPixBaseAddr( myPixMapHandle );
- myRowBytes = (**myPixMapHandle).rowBytes & 0x3fff;
-
- /* Goto 32-bit addressing mode to access pixels */
- mode = true32b;
- SwapMMUMode( &mode );
- for( jjj = 256-1; jjj >= 0; jjj-- )
- {
- *bitsPtr = jjj | (jjj<<8) | (jjj<<16);
- bitsPtr = (long *)((char *)bitsPtr + myRowBytes);
- }
- /* Back to old addressing mode. */
- SwapMMUMode( &mode );
- GetForeColor( &savergb );
- myrgb.red = 0xFFFF;
- myrgb.green = 0;
- myrgb.blue = 0;
- RGBForeColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &srcRect, &thePort->portRect, srcCopy, 0 );
- RGBForeColor( &savergb );
- UnlockPixels( myPixMapHandle );
- }
- DisposeGWorld( myOffGWorld );
- }
-
- void
- CMYColorSeparation()
- {
- Rect dstRect;
- long * bitsPtr;
- RGBColor myrgb, savergb;
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- Rect bounds;
- PicHandle myPicHandle;
-
- #define PICTResID 1000
- #define ditherCopy 0x40
-
- myPicHandle = GetPicture( PICTResID );
- if( !myPicHandle )
- return; /* failed -> exit */
- bounds = (*myPicHandle)->picFrame;
- OffsetRect(&bounds, -bounds.left, -bounds.top); /* To ensure that the scaling below will work for any rect */
- dstRect = bounds;
- dstRect.right *=1.5; /* final image = 1.5 times size of src image */
- dstRect.bottom *=1.5;
- OffsetRect( &dstRect, 20, 20 );
-
- bounds.right *=3; /* Expand by factor of 3 */
- bounds.bottom *=3;
-
- if( NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) == noErr )
- {
- GetGWorld(&oldGW,&oldGD);
- GetForeColor( &savergb );
- SetGWorld(myOffGWorld,nil);
-
- EraseRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- /* myPixMapHandle = myOffGWorld->portPixMap; pre-7.0 */
-
- LockPixels( myPixMapHandle );
- DrawPicture( myPicHandle, &bounds );
-
- SetGWorld(oldGW,oldGD); /* Copy to window */
-
- /* Get the yellow component */
- myrgb.red = 0xFFFF;
- myrgb.green = 0xFFFF;
- myrgb.blue = 0;
- RGBForeColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, 220, 0 );
-
- /* Get the magenta component */
- myrgb.red = 0xFFFF;
- myrgb.green = 0;
- myrgb.blue = 0xFFFF;
- RGBForeColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, -220, 220 );
-
- /* Get the cyan component */
- myrgb.red = 0;
- myrgb.green = 0xFFFF;
- myrgb.blue = 0xFFFF;
- RGBForeColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, 220, 0 );
-
- myrgb.red = 0;
- myrgb.green = 0;
- myrgb.blue = 0;
- RGBForeColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
-
- RGBForeColor( &savergb );
- UnlockPixels( myPixMapHandle );
- DisposeGWorld( myOffGWorld );
- }
- else
- {
- SysBeep(10);
- }
- }
-
- void
- RGBColorSeparation()
- {
- Rect dstRect;
- long * bitsPtr;
- RGBColor myrgb, savergb;
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- Rect bounds;
- PicHandle myPicHandle;
-
- myPicHandle = GetPicture( PICTResID );
- if( !myPicHandle )
- return; /* failed -> exit */
- bounds = (*myPicHandle)->picFrame;
- OffsetRect(&bounds, -bounds.left, -bounds.top); /* To ensure that the scaling below will work for any rect */
- dstRect = bounds;
- dstRect.right *=1.5; /* final image = 1.5 times size of src image */
- dstRect.bottom *=1.5;
- OffsetRect( &dstRect, 20, 20 );
-
- bounds.right *=3; /* Expand by factor of 3 */
- bounds.bottom *=3;
-
- if( NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) == noErr )
- {
- GetGWorld(&oldGW,&oldGD);
- GetForeColor( &savergb );
- SetGWorld(myOffGWorld,nil);
-
- myrgb.red = 0xffff;
- myrgb.green = 0xffff;
- myrgb.blue = 0xffff;
- RGBForeColor( &myrgb );
- PaintRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- /* myPixMapHandle = myOffGWorld->portPixMap; pre-7.0 */
-
- LockPixels( myPixMapHandle );
- DrawPicture( myPicHandle, &bounds );
-
- SetGWorld(oldGW,oldGD); /* Copy to window */
-
- /* Get the red component */
- myrgb.red = 0;
- myrgb.green = 0;
- myrgb.blue = 0;
- RGBForeColor( &myrgb );
- myrgb.red = 0xFFFF;
- myrgb.green = 0;
- myrgb.blue = 0;
- RGBBackColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, 220, 0 );
-
- /* Get the green component */
- myrgb.red = 0;
- myrgb.green = 0xFFFF;
- myrgb.blue = 0;
- RGBBackColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, -220, 220 );
-
- /* Get the blue component */
- myrgb.red = 0;
- myrgb.green = 0;
- myrgb.blue = 0xFFFF;
- RGBBackColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
- OffsetRect( &dstRect, 220, 0 );
-
- myrgb.red = 0;
- myrgb.green = 0;
- myrgb.blue = 0;
- RGBForeColor( &myrgb );
- myrgb.red = 0xffff;
- myrgb.green = 0xffff;
- myrgb.blue = 0xffff;
- RGBBackColor( &myrgb );
- CopyBits( (BitMap *)*myPixMapHandle, &thePort->portBits, &bounds, &dstRect, ditherCopy+srcCopy, 0 );
-
- RGBForeColor( &savergb );
- UnlockPixels( myPixMapHandle );
- DisposeGWorld( myOffGWorld );
- }
- else
- {
- SysBeep(10);
- }
- }
-
- Boolean
- CreatePixMap( PixMap *myPixMap, short hSize, short vSize, short pixDepth )
- {
- #define RGBDirect 16
- long *tmpPtr;
- short rowBytes;
-
- rowBytes = pixDepth*hSize/8;
- rowBytes += rowBytes & 0x0001; /* force rowBytes to be even */
- rowBytes = rowBytes?rowBytes:2; /* force rowBytes >= 2 */
-
- if( (myPixMap->baseAddr = NewPtr( (long)rowBytes*vSize )) == 0 ) /* Allocate PixMap data */
- return( 0 ); /* Abort if noMem */
- myPixMap->rowBytes = rowBytes | 0x8000;
- myPixMap->bounds.top = 0;
- myPixMap->bounds.left = 0;
- myPixMap->bounds.bottom = vSize;
- myPixMap->bounds.right = hSize;
- myPixMap->pmVersion = 0;
- myPixMap->packType = 0;
- myPixMap->packSize = 0;
- myPixMap->hRes = 0x480000;
- myPixMap->vRes = 0x480000;
- myPixMap->pixelType = pixDepth>=16?RGBDirect:0;
- myPixMap->pixelSize = pixDepth;
- myPixMap->cmpCount = pixDepth>=16?3:1;
- myPixMap->cmpSize = pixDepth<16?pixDepth:pixDepth==16?5:8;
- myPixMap->planeBytes = 0;
- if( pixDepth < 16 )
- myPixMap->pmTable = GetCTable( pixDepth );
- else { /* direct: attach a dummy color table to the pixmap */
- myPixMap->pmTable = (CTabHandle)NewHandle( 16 ); /* dummy color table */
- tmpPtr = *(long**)myPixMap->pmTable;
- *tmpPtr++ = (long) pixDepth; /* seed */
- *tmpPtr++ = 0x80000000; /* flags and size-1 */
- *tmpPtr++ = 0x0L; /* value and red */
- *tmpPtr++ = 0x0L; /* green and blue */
- }
- myPixMap->pmReserved = 0;
- return( 1 ); /* success */
- }
-
- void
- DoStretchedCopyBits()
- {
- PixMap srcBits;
- Rect myRect;
- long * bitsPtr;
- long jjj;
- RGBColor myrgb;
- HSVColor myhsv;
-
- #define pixMapHeight 255
-
- if( !CreatePixMap( &srcBits, 1, pixMapHeight, 32 ) )
- return;
- bitsPtr = (long *) srcBits.baseAddr;
-
- myhsv.saturation = MaxSmallFract;
- myhsv.value = MaxSmallFract;
- for( jjj = pixMapHeight-1; jjj >= 0; jjj-- )
- {
- myhsv.hue = jjj << 8;
- HSV2RGB( &myhsv, &myrgb );
- *bitsPtr++ = (((long)(myrgb.red & 0xFF00) | (myrgb.green >> 8)) << 8) | (myrgb.blue>>8);
- }
-
- SetRect( &myRect, 0, 0, 1, pixMapHeight ); /*left, top, right, bottom */
-
- CopyBits( (BitMap *)&srcBits, &thePort->portBits, &myRect, &thePort->portRect, srcCopy, 0 );
-
- DisposHandle( (Handle) (srcBits.pmTable) );
- DisposPtr( srcBits.baseAddr );
- }
-
- DoCopyBitsExample()
- {
- DoColorizedCopyBits();
- }
-
-
-